package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.Params;
import com.stylefeng.guns.modular.system.service.IParamsService;

/**
 * 参数设置控制器
 *
 * @author fengshuonan
 * @Date 2018-07-17 21:42:09
 */
@Controller
@RequestMapping("/params")
public class ParamsController extends BaseController {

    private String PREFIX = "/system/params/";

    @Autowired
    private IParamsService paramsService;

    /**
     * 跳转到参数设置首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "params.html";
    }

    /**
     * 跳转到添加参数设置
     */
    @RequestMapping("/params_add")
    public String paramsAdd() {
        return PREFIX + "params_add.html";
    }

    /**
     * 跳转到修改参数设置
     */
    @RequestMapping("/params_update/{paramsId}")
    public String paramsUpdate(@PathVariable Integer paramsId, Model model) {
        Params params = paramsService.selectById(paramsId);
        model.addAttribute("item",params);
        LogObjectHolder.me().set(params);
        return PREFIX + "params_edit.html";
    }

    /**
     * 获取参数设置列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return paramsService.selectList(null);
    }

    /**
     * 新增参数设置
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Params params) {
        paramsService.insert(params);
        return SUCCESS_TIP;
    }

    /**
     * 删除参数设置
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer paramsId) {
        paramsService.deleteById(paramsId);
        return SUCCESS_TIP;
    }

    /**
     * 修改参数设置
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Params params) {
        paramsService.updateById(params);
        return SUCCESS_TIP;
    }

    /**
     * 参数设置详情
     */
    @RequestMapping(value = "/detail/{paramsId}")
    @ResponseBody
    public Object detail(@PathVariable("paramsId") Integer paramsId) {
        return paramsService.selectById(paramsId);
    }
}
